const code = require("../models/code")

var express = require('express');
var router = express.Router();

const formidable = require('formidable');

router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
            code.findById(fields.id, (err, code) => {
                if(err) {
                    res.json({'state': false, 'msg': err})
                }else {
                    res.json({
                        'state': true,
                        'code': code
                    })
                }
            })
        }

    });

});

module.exports = router;